package com.szrt.cll.test.core.base;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

public abstract class BaseServiceImpl<T> implements BaseService<T>{

	//访问数据库
	public abstract BaseDao<T> getBaseDao();
	
	/**
	 * 添加数据
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	public int add(T entity) {
	
		return getBaseDao().insert(entity);
	}
	
	/**
	 * 批量删除数据
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	public int deleteByIds(List<Integer> ids) {
		
		return getBaseDao().deleteByIds(ids);
	}

	/**
	 * 单个删除数据
	 */	
	@Override
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	public int deleteById(Integer id) {
		
		return getBaseDao().deleteByPrimaryKey(id);
	}
	
	/**
	 * 修改数据
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	public int update(T entity) {
		
		return getBaseDao().updateByPrimaryKey(entity);
	}
	
	/**
	 *查询数据
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	public T findById(Integer id) {
		
		return getBaseDao().selectByPrimaryKey(id);
	}

	@Override
	public List<T> findAll(Map<String, Object> pageMap) {
		
		return getBaseDao().selectAll();
	}

	

}
